import axios from "axios";
import type { AxiosInstance, InternalAxiosRequestConfig } from "axios";
import { createDiscreteApi } from "naive-ui";
const { message } = createDiscreteApi(["message"]);
const request: AxiosInstance = axios.create({
  baseURL: import.meta.env.VITE_GLOB_API_URL,
  timeout: 20000,
});
// 请求拦截器
request.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    return config;
  },
  (error) => {
    console.log(error);
    Promise.reject(error);
  },
);
// 添加响应拦截器
request.interceptors.response.use(
  function (response) {
    // 响应结果
    // console.log("response", response);
    if (response.data.code == 500) {
      // 错误弹窗提示
      message.error(response.data.msg);
    }
    return response.data;
  },
  function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  },
);

/* export const successApi = ()=>{
  return request({
    url:"/success",
    method:"post"
  })
} */

export default request;
